<template>
  <div class="home">
    <scroll-view class="scrollview" :scroll-y="true">
      <div class="header">
        <image
          class="header-bg"
          src="https://ysgapi.yfzxzjysg.top/bg.png"
          mode=""
        />
        <u-search
          placeholder="走进艺术宫"
          :showAction="false"
          :disabled="true"
          v-model="searchValue"
          @click="onSearchClick"
        ></u-search>
        <!-- <div class="searchList">
          <div class="search-item">海阔天空</div>
          <div class="search-item">海阔天空</div>
          <div class="search-item">海阔天空</div>
        </div> -->
      </div>
      <!-- banner -->
      <div style="background: #fff">
        <div class="banner">
          <u-swiper
            :list="banner"
            indicator
            keyName="img"
            indicatorMode="line"
            circular
            @click="onBannerClick"
          ></u-swiper>
        </div>
        <!-- 最近活动 -->
        <div class="actron">
          <div class="actron-header">
            <view> 最近活动 </view>
            <div class="actron-right">更多活动</div>
          </div>
          <div @click="onlineDetail">
            <div class="actron-image">
              <image :src="active.cover" mode="widthFix" />
            </div>
            <div class="title">{{ active.name || "" }}</div>
            <div class="desc">
              <u--text
                :lines="3"
                color="#666666"
                size="24rpx"
                :text="active.content"
              ></u--text>
            </div>
          </div>
          <div style="margin: 40rpx 0">
            <u--image
              :showLoading="true"
              :src="require('@/assets/home-bottom.png')"
              width="100%"
              height="154rpx"
              radius="9rpx"
            ></u--image>
          </div>
        </div>
      </div>
    </scroll-view>
    <u-modal
      :show="show"
      @confirm="confirm"
      @cancel="cancel"
      confirmText="去登录"
      :showCancelButton="true"
      ref="uModal"
      title="提示"
      content="同学，想要看更多内容请先去登录！"
      :asyncClose="true"
    ></u-modal>
  </div>
</template>

<script>
import { get_activity, get_banner } from "apis/modules/user";
import { getStorage, setStorage } from "@/utils/auth";
export default {
  name: "Home",
  data() {
    return {
      show: false,
      searchValue: "",
      list1: [
        "https://cdn.uviewui.com/uview/swiper/swiper1.png",
        "https://cdn.uviewui.com/uview/swiper/swiper2.png",
        "https://cdn.uviewui.com/uview/swiper/swiper3.png",
      ],
      banner: [],
      active: {},
    };
  },
  // 分享到朋友圈
  onShareTimeline: function (res) {
    return {
      title: "走进艺术宫",
    };
  },
  onShareAppMessage(res) {
    return {
      title: "走进艺术宫",
    };
  },
  onShow() {
    uni.showShareMenu();
    this.getBanner();
    this.getActivity();
  },
  methods: {
    confirm() {
      this.$Router.push({
        path: "/pages/login/login",
      });
      setTimeout(() => {
        this.show = false;
      }, 500);
    },
    cancel() {
      this.show = false;
    },
    onBannerClick(index) {
      let bannerItem = this.banner[index];
      console.log(bannerItem);
      this.onDetail(bannerItem);
    },
    // 获取banner
    getBanner() {
      let school_id = getStorage("school_id");
      get_banner({ school_id })
        .then((result) => {
          this.banner = result;
        })
        .catch((err) => {});
    },
    // 获取线下活动
    getActivity() {
      let data = {
        page: 1,
        limit: 1,
        school_id: getStorage("school_id"),
      };
      get_activity(data).then((result) => {
        this.active = result[0];
      });
    },
    onDetail(bannerItem, is) {
      let token = !!getStorage("token");
      if (token) {
        if (bannerItem.type !== 1) {
          return;
        }
        console.log(bannerItem, is);
        if (is) {
          this.$Router.push({
            path: `/pagesA/offlineDetail/offlineDetail?course_id=${this.active.id}`,
          });
          return;
        }
        if (bannerItem.course_type == 1) {
          this.$Router.push({
            path: `/pagesA/onlineDetail/onlineDetail?course_id=${bannerItem.course_id}`,
          });
        } else {
          this.$Router.push({
            path: `/pagesA/offlineDetail/offlineDetail?course_id=${bannerItem.course_id}`,
          });
        }
      } else {
        this.show = true;
      }
    },
    onlineDetail() {
      let token = !!getStorage("token");
      if (token) {
        this.$Router.push({
          path: `/pagesA/offlineDetail/offlineDetail?course_id=${this.active.id}`,
        });
      } else {
        this.show = true;
      }
    },
    onSearchClick() {
      let token = !!getStorage("token");
      if (token) {
        this.$Router.push({
          path: "/pages/searchPage/index",
        });
      } else {
        this.show = true;
      }
    },
  },
};
</script>
<style lang="scss">
.home {
  height: 100vh;
  .scrollview {
    height: 100%;
    overflow: hidden;
    // background: #eeeeee;
    background: #fff;
  }
  .header {
    padding: 180rpx 40rpx 40rpx;
    box-sizing: border-box;
    background: rgba(0, 0, 0, 0);
    position: relative;
    z-index: 1;
    overflow: hidden;
    &::after {
      content: "欢迎进入      走进艺术宫";
      position: absolute;
      top: 70rpx;
      left: 40rpx;
      width: 110rpx;
      color: #fff;
      font-size: 22rpx;
    }
    .header-bg {
      position: absolute;
      z-index: -1;
      width: 100%;
      height: 100%;
      top: 0;
      left: 0;
    }
    .searchList {
      display: flex;
      .search-item {
        width: 200rpx;
        height: 55rpx;
        text-align: center;
        line-height: 55rpx;
        color: #fff;
        margin-top: 20rpx;
        margin-right: 20rpx;
        border-radius: 55rpx;
        background: rgba(255, 255, 255, 0.35);
        box-shadow: 0rpx 3rpx 6rpx 1rpx rgba(0, 0, 0, 0.16);
      }
    }
  }
  .banner {
    margin: 0 30rpx;
    background: #fff;
    padding: 30rpx 0;
  }
  .actron {
    margin: 0 40rpx;
    background: #fff;
    .actron-header {
      display: flex;
      justify-content: space-between;
      align-items: center;
      font-size: 34rpx;
      font-weight: 700;
      padding: 20rpx;
      .actron-right {
        font-weight: 400;
        font-size: 24rpx;
        color: rgba(175, 175, 175, 0.6);
      }
    }
    .actron-image {
      border-radius: 20rpx;
      min-height: 305rpx;
      overflow: hidden;
      image {
        width: 100%;
        height: 100%;
      }
    }
    .title {
      font-size: 28rpx;
      font-weight: 600;
      margin: 16rpx 0;
      padding: 0 20rpx;
    }
    .desc {
      color: #666666;
      font-size: 24rpx;
      padding: 0 20rpx;
    }
  }
}
</style>
